//
//  UITabBarController+LFExtension.m
//  aiXianMian
//
//  Created by qianfeng on 15/10/26.
//  Copyright (c) 2015年 QianFeng. All rights reserved.
//

#import "UITabBarController+LFExtension.h"

@implementation UITabBarController (LFExtension)

- (void)addViewController:(UIViewController *)vc
                    title:(NSString *)title
                    image:(NSString *)image
            selectedImage:(NSString *)seletedImage {
    
    // 1. 设置标题
    vc.title = title;
    
    // 2. 做导航视图控制器
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    
    UIImage *imageNormal = [UIImage imageNamed:image];
    imageNormal = [self originalImage:imageNormal];
    
    UIImage *imageSeleted = [UIImage imageNamed:seletedImage];
    imageSeleted = [self originalImage:imageSeleted];
    
    // 3.
    nav.tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:imageNormal selectedImage:imageSeleted];
    
    // 4.
    [self addChildViewController:nav];
}

#pragma mark ------originalImage------
- (UIImage *)originalImage:(UIImage *)image {
    if ([UIDevice currentDevice].systemVersion.floatValue >= 7.0) {
        image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }
    return image;
}

@end
